]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
app-system: Improve StartupWMClass heuristics
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 26 Jun 2015 11:46:11 +0000 (13:46 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Fri, 26 Jun 2015 17:21:46 +0000 (19:21 +0200)
Our StartUpWMClass heuristics use a StartupWMClass -> .desktop ID
mapping built from the list of all installed applications. In case
of multiple .desktop files setting the same StartupWMClass, we
currently simply pick the last one returned by g_app_info_get_all (),
which can be a bit surprising:
A window with WM_CLASS 'emacs', launched through a .desktop file
named 'emacs.desktop' with a StartupWMClass of 'emacs' maps to ...
'emacsclient.desktop'!
Make this case a bit less random by preferring the app info whose
ID matches the StartupWMClass.

https://bugzilla.gnome.org/show_bug.cgi?id=751541

src/shell-app-system.c

index ff838f9794b53aed67536782246d2152fca8e4db..a45da0d617a59d1754c8ed0c01ce259331fb8182 100644 (file)
@@ -83,12 +83,18 @@ scan_startup_wm_class_to_id (ShellAppSystem *self)
   for (l = apps; l != NULL; l = l->next)
     {
       GAppInfo *info = l->data;
-      const char *startup_wm_class, *id;
+      const char *startup_wm_class, *id, *old_id;
 
       id = g_app_info_get_id (info);
       startup_wm_class = g_desktop_app_info_get_startup_wm_class (G_DESKTOP_APP_INFO (info));
 
-      if (startup_wm_class != NULL)
+      if (startup_wm_class == NULL)
+        continue;
+
+      /* In case multiple .desktop files set the same StartupWMClass, prefer
+       * the one where ID and StartupWMClass match */
+      old_id = g_hash_table_lookup (priv->startup_wm_class_to_id, startup_wm_class);
+      if (old_id == NULL || strcmp (id, startup_wm_class) == 0)
         g_hash_table_insert (priv->startup_wm_class_to_id,
                              g_strdup (startup_wm_class), g_strdup (id));
     }